home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 June / Cd Pc Users 9.iso / prog / inst / baslibs / frmtrayi.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-29  |  3.0 KB  |  104 lines

  1. VERSION 4.00
  2. Begin VB.Form frmTrayIcon 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    BorderStyle     =   0  'None
  6.    ClientHeight    =   1620
  7.    ClientLeft      =   4155
  8.    ClientTop       =   4590
  9.    ClientWidth     =   2700
  10.    Height          =   2025
  11.    Icon            =   "frmTrayIcon.frx":0000
  12.    Left            =   4095
  13.    LinkTopic       =   "Form1"
  14.    LockControls    =   -1  'True
  15.    ScaleHeight     =   1620
  16.    ScaleWidth      =   2700
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   4245
  19.    Visible         =   0   'False
  20.    Width           =   2820
  21. Attribute VB_Name = "frmTrayIcon"
  22. Attribute VB_Creatable = False
  23. Attribute VB_Exposed = False
  24. Option Explicit
  25. Private Type NOTIFYICONDATA
  26.     cbSize As Long
  27.     hwnd As Long
  28.     uId As Long
  29.     uFlags As Long
  30.     ucallbackMessage As Long
  31.     hIcon As Long
  32.     szTip As String * 64
  33. End Type
  34. Private Const NIM_ADD = &H0
  35. Private Const NIM_MODIFY = &H1
  36. Private Const NIM_DELETE = &H2
  37. Private Const WM_MOUSEMOVE = &H200
  38. Private Const NIF_MESSAGE = &H1
  39. Private Const NIF_ICON = &H2
  40. Private Const NIF_TIP = &H4
  41. Private IconIsOn As Boolean
  42. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
  43. Private t As NOTIFYICONDATA
  44. Public Owner As Form
  45. Public ShowTray As Boolean
  46. ' Set's which object to call "TrayIconCallback(msg As Long)" in.
  47. Public Sub SetCallback(ob As Object)
  48.    Set Owner = ob
  49. End Sub
  50. '  Turns the Trayicon on and off.
  51. '  Note: the Icon, and ToolTip are taken from the
  52. '        form's icon and caption respectively.
  53. Public Sub Update(IconOn As Boolean)
  54.    If IconOn Then
  55.       t.cbSize = Len(t)
  56.       t.hwnd = Me.hwnd
  57.       t.uId = 1&
  58.       t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  59.       If Me.Caption <> "" Then
  60.          t.uFlags = t.uFlags Or NIF_TIP
  61.       End If
  62.       t.ucallbackMessage = WM_MOUSEMOVE
  63.       t.hIcon = Me.icon
  64.       t.szTip = Me.Caption & Chr$(0)
  65.       
  66.       If Not IconIsOn Then
  67.          Shell_NotifyIcon NIM_ADD, t
  68.       Else
  69.          Shell_NotifyIcon NIM_MODIFY, t
  70.       End If
  71.       IconIsOn = True
  72.    Else
  73.       If IconIsOn Then
  74.          t.cbSize = Len(t)
  75.          t.hwnd = Me.hwnd
  76.          t.uId = 1&
  77.          Shell_NotifyIcon NIM_DELETE, t
  78.       End If
  79.       IconIsOn = False
  80.    End If
  81. End Sub
  82. Private Sub Form_Load()
  83.    IconIsOn = False
  84. End Sub
  85. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  86.     Static rec As Boolean, msg As Long
  87.     msg = X / Screen.TwipsPerPixelX
  88.     If rec = False Then
  89.         rec = True
  90.         
  91.         ' Ignore an error if the call to
  92.         ' Owner.TrayIconCallback fails
  93.         On Error Resume Next
  94.         If msg >= WM_LBUTTONDOWN And msg <= WM_RBUTTONDBLCLK Then
  95.            Call Owner.TrayIconCallback(msg)
  96.         End If
  97.         
  98.         rec = False
  99.     End If
  100. End Sub
  101. Private Sub Form_Unload(Cancel As Integer)
  102.    Me.Update False
  103. End Sub
  104.